import dayjs from 'dayjs';
import { cloneDeep } from 'lodash';

export const certiOptions = [
  {
    value: 'jyz',
    label: '结业证书',
  },
  {
    value: 'shsjz',
    label: '活动证书',
  },
  {
    value: 'jshyz',
    label: '注册教师证书',
  },
  {
    value: 'hzdwz',
    label: '合作单位证书',
  },
];

export const categoryOptions = [
  {
    value: 'first',
    label: '首次审核',
  },
  {
    value: 'expiry',
    label: '到期审核',
  },
];

export const categoryMap = {
  first: '首次审核',
  reopen: '到期审核',
};

export const certiOptions2 = [
  {
    value: 'jyz',
    label: '结业证书',
  },

  {
    value: 'shsjz',
    label: '活动证书',
  },
];

export const certiMap = {
  jyz: '结业证书',
  jshyz: '注册教师证书',
  hzdwz: '合作单位证书',
  shsjz: '活动证书',
};

export const statusOptions = [
  {
    value: 0,
    label: '待审核',
  },
  // {
  //   value: 1,
  //   label: '审核中',
  // },
  {
    value: 2,
    label: '不通过',
  },
  {
    value: 3,
    label: '审批通过',
  },
  {
    value: 5,
    label: '待缴费',
  },
  {
    value: 9,
    label: '已办结',
  },
];

export const statusMap = {
  0: '待审核',
  1: '审核中',
  2: '不通过',
  3: '审批通过',
  5: '待缴费',
  9: '已办结',
};

export const certiStatusOptions = [
  {
    value: 2,
    label: '已下线',
  },
  {
    value: 0,
    label: '生效中',
  },
  {
    value: 1,
    label: '已过期',
  },
];

export const setOptions = [
  {
    label: '男',
    value: '男',
  },
  {
    label: '女',
    value: '女',
  },
];

export const certiStatusMap = {
  0: '生效中',
  1: '已过期',
  2: '已下线',
};

export const baseInfoPersonForm = [
  {
    label: '个人照片',
    key: 'photoPath',
    type: 'image',
  },
  {
    label: '申请类别',
    key: 'category',
    type: 'select',
    options: categoryOptions,
    optional: true,
  },
  {
    label: '姓名',
    key: 'name',
    type: 'string',
    required: true,
    example: '张三',
  },
  {
    label: '拼音',
    key: 'pinyin',
    type: 'string',
    optional: true,
  },
  {
    label: '性别',
    key: 'gender',
    type: 'select',
    optional: true,
    options: [
      {
        label: '男',
        value: '男',
      },
      {
        label: '女',
        value: '女',
      },
    ],
  },
  {
    label: '出生年月',
    key: 'birthDate',
    type: 'date',
    optional: true,
  },
  {
    label: '民族',
    key: 'nation',
    type: 'string',
    optional: true,
  },
  {
    label: '居住所在地',
    key: 'address',
    type: 'string',
    optional: true,
  },
  {
    label: '籍贯',
    key: 'nativePlace',
    type: 'string',
    optional: true,
  },
  {
    label: '政治面貌',
    key: 'politicalAffiliation',
    type: 'string',
    optional: true,
  },
  {
    label: '联系电话',
    key: 'mobile',
    type: 'string',
    optional: true,
  },
  {
    label: '邮箱',
    key: 'email',
    type: 'string',
    optional: true,
  },
  // {
  //   label: '证件类型',
  //   key: 'cardType',
  //   type: 'string',
  //   optional: true,
  //   example: '2',
  // },
  {
    label: '身份证号码',
    key: 'cardNo',
    type: 'string',
    optional: true,
  },
  {
    label: '邮寄地址',
    key: 'mailAddress',
    type: 'string',
    optional: true,
  },
  {
    label: '教育背景',
    key: 'eduBg',
    type: 'string',
    optional: true,
  },
  {
    label: '工作经历',
    key: 'workExperience',
    type: 'textarea',
    optional: true,
  },
  {
    label: '所获荣誉',
    key: 'honors',
    type: 'textarea',
    optional: true,
  },
  {
    label: '推荐机构(推荐人)',
    key: 'recommend',
    type: 'string',
    optional: true,
  },
  {
    label: '所在地区',
    key: 'region',
    type: 'area',
    optional: true,
  },
];

export const baseInfoPersonForm2 = [
  {
    label: '申请类别',
    key: 'category',
    type: 'select',
    options: categoryOptions,
    optional: true,
  },
  {
    key: 'name',
    type: 'string',
    label: '单位名称',
    required: true,
    example: '李四',
  },
  {
    key: 'address',
    type: 'string',
    label: '单位地址',
    required: false,
  },
  {
    key: 'subjection',
    type: 'select',
    label: '隶属管辖',
    required: false,
    options: [
      {
        label: '工商',
        value: '工商',
      },
      {
        label: '教委',
        value: '教委',
      },
    ],
  },
  {
    key: 'establishmentDate',
    type: 'date',
    label: '机构成立时间',
    required: false,
  },
  {
    key: 'contactUser',
    type: 'string',
    label: '单位负责人',
    required: false,
  },
  {
    key: 'contactPhone',
    type: 'string',
    label: '联系电话',
    required: false,
  },
  {
    key: 'contactPosition',
    type: 'string',
    label: '担任职务',
    required: false,
  },
  {
    key: 'campusCount',
    type: 'integer',
    format: 'int32',
    label: '校区数量',
    required: false,
    example: 27129,
  },
  {
    key: 'totalCampusArea',
    type: 'number',
    format: 'double',
    label: '校区总面积(平方米)',
    required: false,
  },
  {
    key: 'studentAgeRange',
    type: 'rangenumber',
    label: '学员年龄区间',
    required: false,
  },

  {
    key: 'studentsCount',
    type: 'number',
    format: 'int32',
    label: '舞蹈生在籍人数',
    required: false,
    example: 1499,
  },
  {
    key: 'ftTeachersCount',
    type: 'number',
    format: 'int32',
    label: '全职教师人数',
    required: false,
    example: 32332,
  },
  {
    key: 'gradingSystem',
    type: 'string',
    label: '考级体系',
    required: false,
  },

  {
    key: 'recommend',
    type: 'string',
    label: '推荐单位(推荐人)',
    required: false,
  },
  {
    key: 'region',
    type: 'area',
    label: '所在地区',
    required: false,
  },
  {
    key: 'mainCourses',
    type: 'textarea',
    label: '主营课程',
    required: false,
  },
  {
    key: 'description',
    type: 'textarea',
    label: '单位介绍',
    required: false,
    example: '你说的对',
  },
];

export const applyDataAdapter = (data) => {
  if (data.region instanceof Array) {
    data.region = data?.region?.join(',');
  }

  return data;
};

export const initDataAdapter = (data) => {
  return {
    ...data,
    birthDate: data.birthDate ? dayjs(data.birthDate) : null,
    startTime: data.startTime ? dayjs(data.startTime) : null,
    endTime: data.endTime ? dayjs(data.endTime) : null,
    expiryDate: data.expiryDate ? dayjs(data.expiryDate) : null,
    establishmentDate: data.establishmentDate ? dayjs(data.establishmentDate) : null,
  };
};

export const reqDataAdapter = (data) => {
  const nData = cloneDeep(data);
  nData.startTime = !nData.startTime
    ? null
    : dayjs(nData.startTime).startOf('day').hour(0).format('YYYY-MM-DD HH:mm:ss');
  nData.endTime = !nData.endTime
    ? null
    : dayjs(nData.endTime)
        .startOf('day')
        .hour(23)
        .minute(59)
        .second(59)
        .format('YYYY-MM-DD HH:mm:ss');
  nData.birthDate = !nData.birthDate ? null : dayjs(nData.birthDate).format('YYYY-MM-DD');
  nData.expiryDate = !nData.expiryDate ? null : dayjs(nData.expiryDate).format('YYYY-MM-DD');
  return nData;
};
